using UnityEngine;
using UnityEngine.UI;

public class DodgeSillController : Skill
{
    [Header("Dodge")]
    [SerializeField] private UiSkillTreeSlot unlockDodgeButton;
    [SerializeField] private int evasionAmount;
    public bool dodgeUnlocked;
    [Header("Mirage dodge")]
    [SerializeField] private UiSkillTreeSlot unlockMirageButton;
    public bool dodgeMirageUnlocked;

    protected override void Start()
    {
        base.Start();
        unlockDodgeButton.GetComponent<Button>().onClick.AddListener(UnlockDodge);
        unlockMirageButton.GetComponent<Button>().onClick.AddListener(UnlockMirageDodge);
    }

    protected override void CheckUnlock()
    {
        UnlockDodge();
        UnlockMirageDodge();
    }

    private void UnlockDodge()
    {
        if (!unlockDodgeButton.unlocked || dodgeUnlocked) return;
        Player.Stats.evasion.AddModifier(evasionAmount);
        Inventory.Instance.UpdateStatsUi();
        dodgeUnlocked = true;
    }

    private void UnlockMirageDodge()
    {
        if (!unlockMirageButton.unlocked || dodgeMirageUnlocked) return;
        dodgeMirageUnlocked = true;
    }

    public void CreateMirageOnDodge()
    {
        if (dodgeMirageUnlocked)
            SkillManager.Instance.Clone.Create(Player.transform);
    }
}